package com.jdk.learn.juc2;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 类功能描述:
 *  多线程基础
 * @author bgt
 * @version V1.0
 * @since 2019-01-30 15:32
 */
public class multithreadbase {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        new myFirstThread().start();
        new Thread(new MyRunnable()).start();
        FutureTask<String> task = new FutureTask<>(new MyFutureTaskCallable());
        new Thread(task).start();
        System.out.println(task.get());
    }
}

/**
 * 方式1 继承thread
 */
class myFirstThread extends Thread{
    @Override
    public void run() {
        System.out.println("myFirstThread running");
    }
}

/**
 * 方式2 实现 Runnable
 */
class MyRunnable implements Runnable{

    @Override
    public void run() {
        System.out.println("MyRunnable running");
    }
}


class MyFutureTaskCallable implements Callable<String>{

    @Override
    public String call() throws Exception {
        return "ricky:MyFutureTaskCallable running";
    }
}

